package com.example.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MySQLiteHelper extends SQLiteOpenHelper{

	  public static final String TABLE_PROFILE = "tb_profile";
	  //person
	  public static final String COLUMN_ID          = "_id";
	  public static final String COLUMN_EMAIL       = "_email";
	  public static final String COLUMN_PASSWORD    = "_password";
	  public static final String COLUMN_FULL_NAME   = "_full_name";
	  public static final String COLUMN_FIRST_NAME  = "_first_name";
	  public static final String COLUMN_LAST_NAME   = "_last_name";
	  public static final String COLUMN_GENDER        = "_gender";
	  public static final String COLUMN_BIRTHDAY      = "_birthday";
	  public static final String COLUMN_MOBILE        = "_mobile";
	  public static final String COLUMN_HOME_PHONE    = "_home_phone";
	  public static final String COLUMN_HOME_ADDRESS  = "_home_address";
	  // company
	  public static final String COLUMN_COMPANY_ADDRESS = "_company_adress";
	  public static final String COLUMN_COMPANY_PHONE   = "_company_phone";
	  public static final String COLUMN_COMPANY_NAME    = "_company_name";
	  public static final String COLUMN_COMPANY_EMAIL = "_company_email";
	  public static final String COLUMN_COMPANY_WEBSITE = "_company_website";
	  
	  
	  public static final String DATABASE_NAME = "db_appcontact.db";
	  private static final int DATABASE_VERSION = 1;

	  // Database creation sql statement
	  private static final String DATABASE_CREATE = "create table " + TABLE_PROFILE + 
			  "(" + COLUMN_ID         + " INTEGER NOT NULL, " + 
			  COLUMN_EMAIL            + " NVARCHAR(50) NOT NULL, " +
			  COLUMN_FIRST_NAME       + " NVARCHAR(50), "          +
			  COLUMN_LAST_NAME        + " NVARCHAR(50), " 		  +
			  COLUMN_GENDER           + " INTEGER NOT NULL default 0, "      + // 0: None | 1: Male | 2: Female
			  COLUMN_BIRTHDAY         + " VARCHAR(20)  default '',"             +
			  COLUMN_MOBILE           + " VARCHAR(20)  ,"             +
			  COLUMN_HOME_PHONE       + " VARCHAR(50), "           +
			  COLUMN_HOME_ADDRESS     + " VARCHAR(50), "           +
			  // company
			  COLUMN_COMPANY_NAME     + " VARCHAR(50), "           +
			  COLUMN_COMPANY_WEBSITE  + " TEXT,"                    +
			  COLUMN_COMPANY_EMAIL  + " TEXT, "                 +
			  COLUMN_COMPANY_PHONE    + " TEXT, "                 +
			  COLUMN_COMPANY_ADDRESS    + " TEXT "                  +
			   	
			  
			  ");";
	

	  public MySQLiteHelper(Context context) {
	    super(context, DATABASE_NAME, null, DATABASE_VERSION);
	  }

	  @Override
	  public void onCreate(SQLiteDatabase database) {
	    database.execSQL(DATABASE_CREATE);
	  }

	  @Override
	  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	    Log.w(MySQLiteHelper.class.getName(),
	        "Upgrading database from version " + oldVersion + " to "
	            + newVersion + ", which will destroy all old data");
	    db.execSQL("DROP TABLE IF EXISTS " + TABLE_PROFILE);
	    onCreate(db);
	  }
}
